package com.woniu.controller;

import com.woniu.entity.PageResult;
import com.woniu.entity.Result;
import com.woniu.pojo.Label;
import com.woniu.service.ILabelService;
import com.woniu.vo.LabelQueryVo;
import com.woniu.vo.OrganizationQueryVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 标签（病例表） 前端控制器
 * </p>
 *
 * @author doujiao
 * @since 2022-10-12
 */
@RestController
@RequestMapping("/label")
@Api(tags = "标签模块")
public class LabelController extends BaseController{

    @Resource
    private ILabelService labelService;
    /**
     * 查所有
     */
    @GetMapping
    @ApiOperation("查所有")
    public Result queryAll(){
        List<Label> list = labelService.list();
        return toDataResult(list);
    }
    /**
     * 根据id查询
     */
    @GetMapping("/{id}")
    public Result queryById(@PathVariable Long id){
        Label Label = labelService.getById(id);
        return toDataResult(Label);
    }

    /**
     * 增加
     */
    @PostMapping
    @ApiOperation("增加一条")
    public Result add(@RequestBody Label label){
        boolean save = labelService.save(label);
        return toResult(save);
    }
    /**
     * 编辑
     */
    @PutMapping
    @ApiOperation("编辑一条")
    public Result edit(@RequestBody Label label){
        boolean result = labelService.updateById(label);
        return toResult(result);
    }
    /**
     * 根据id删除
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除")
    public Result removeById(@PathVariable Long id){
        boolean result = labelService.removeById(id);
        return toResult(result);
    }

    @ApiOperation("搜索+分页")
    @PostMapping("/search/{currentPage}/{pageSize}")
    public Result search(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody LabelQueryVo labelQueryVo){
        PageResult pageResult = labelService.search(currentPage, pageSize, labelQueryVo);
        return toDataResult(pageResult);
    }

    @ApiOperation("根据标签id来修改标签状态")
    @PutMapping("/status/{labelId}")
    public Result updateStatusByIdd(@PathVariable Long labelId){
        boolean flag = labelService.updateStatusById(labelId);
        return toDataResult(flag, "修改标签状态成功");
    }
}
